<template>
	<om-page :title="pageTitle">
		<view v-if="hasLogin">
			<transition name="fade">
			<view v-show="promotionShow" class="promotion om-btn-color">
				<view class="cont">
					<view>素伊OM系统</view>
					<view>Operation&Management</view>
					<view>{{ processFormCount }} 张流程表单</view>
					<view>{{ registrationFormCount }} 张统计/登记表</view>
					<view>让企业管理变得简单</view>
				</view>
			</view>
			</transition>
			<!-- #ifdef APP-PLUS -->
			<view class="topbg om-btn-color"></view>
			<!-- #endif -->
			<view class="topcont om-btn-color">
				<view class="topcont-org"><ot-sl-filter :ref="'slFilter'" :topFixed="true" :menuList="filterList" @result="onChangeFilter" /></view>
				<!-- #ifdef APP-PLUS -->
				<view class="topcont-more" @click="operateMore"></view>
				<view class="topcont-more-sjx" v-show="operateShow"></view>
				<view class="topcont-more-list" v-show="operateShow">
					<view class="single wechat" @click="scanHandle">扫一扫</view>
				</view>
				<!-- #endif -->
			</view>
			<om-topbutton class="om-topbutton" style="z-index: 1000000;" :hasBgColor="true" placeHolder="快速查找同事" @click='searchTab'></om-topbutton>
			<view class="page__bd">
				<view class="affairs" :style="{'margin-top':topButtonHeight+'px'}">
					<view v-if="orgImages.length" :style="{'margin-top':'0px',width:'100%;'}">
						<om-swiper style="height:75px;" :datas="orgImages"></om-swiper>
					</view>
					<view class="" v-else :style="{'margin-top':'0px',width:'100%;'}">
						<image style="width:100%;height:75px;" src="/static/images/others/noImg.png" mode="aspectFill"></image>
					</view>
					<tui-grid  style="height: 80rpx;">
						<tui-grid-item :index="3" style="height: 80rpx; text-align:center;display:flex; align-items: center;justify-content: center;" :cell="4" @click="headChange">
							<span class="tui-grid-label">
								{{ notifyMenuList[3].title }}
								<uni-badge style=" transform-origin: 100% -20%;" :text="total3" size="small" type="error"></uni-badge>
							</span>
						</tui-grid-item>
						<tui-grid-item :index="0" style=" height: 80rpx;text-align:center;display:flex;align-items: center;justify-content: center;" :cell="4" @click="headChange">
							<span class="tui-grid-label">
								{{ notifyMenuList[0].title }}
							</span>
						</tui-grid-item>
						<tui-grid-item :index="1" style=" height: 80rpx; text-align:center;display:flex;align-items: center;justify-content: center;" :cell="4" @click="headChange">
							<span class="tui-grid-label">
								{{ notifyMenuList[1].title }}
								<uni-badge style="transform-origin: 100% -20%;" :text="total" size="small" type="error"></uni-badge>
							</span>
						</tui-grid-item>
						<tui-grid-item :index="2" style="height: 80rpx;text-align:center;display:flex;align-items: center;justify-content: center;" :cell="4" @click="headChange">
							<span class="tui-grid-label">
								{{ notifyMenuList[2].title }}
								<uni-badge style="transform-origin: 100% -20%;" :text="total2" size="small" type="error"></uni-badge>
							</span>
						</tui-grid-item>
					</tui-grid>
				</view>
				<view class="box-cont">
					<view class="tit-bar" :style="{'padding-top':marginTopAffairs}">
						<view class="tit">常用#</view>
						<view>
							<cmd-icon color="#333" size="12" type="edit" @click="commonEdit">
								<text>编辑</text>
							</cmd-icon>
						</view>
					</view>
					<view class="cont">
						<uni-card  style="border:none;" :titleUnderline="false" :is-full="true">
							<om-menu :menuList="commonMenuLit" :colLen="5" :bordered="false" fontSize="small" :defaultImg="true"></om-menu>
						</uni-card>
						<view style="height: 6px" class="bg-gray"></view>
					</view>
				</view>
				<template v-for="item in allGroupList">
					<view style="height: 5px;width: 100%;"></view>
					<view class="box-cont">
						<view class="tit-bar">
							<view class="tit">{{ item.groupName }}</view>
							<view @click="groupManager(item)" v-show="isadmin == true">
								<image class="manager-icon" :src="'/static/images/others/manager.png'"></image>
								<text>管理</text>
							</view>
						</view>
						<view class="cont">
							<uni-card  style="border:none;" :titleUnderline="false" :is-full="true">
								<om-menu :menuList="item.menuList" :colLen="5" :bordered="false" fontSize="small" :dataScore="1" :defaultImg="true"></om-menu>
							</uni-card>
							<view style="height: 6px" class="bg-gray"></view>
						</view>
					</view>
				</template>
				<view style="height: 5px;width: 100%;" v-show="isadmin == true"></view>
				<view class="group-menu" @click="groupSetting" v-show="isadmin == true">菜单分组</view>
				<!-- <view style="height: 6px;width: 100%;" v-show="isadmin == true" class="bg-gray"></view>
				<view class="group-menu sync" @click="groupSync" v-show="isadmin == true">菜单同步</view> -->
				<view class="box-cont" v-show="isadmin == true">
					<view class="cont" style="padding-top: 0;">
						<view style="height: 6px" class="bg-gray"></view>
					</view>
				</view>
				<view class="box-cont">
					<view class="tit-bar">
						<view class="tit">功能应用展示</view>
						<!-- <view>
							<cmd-icon color="#333" size="12" type="edit" @click="sceneEdit">
								<text>编辑</text>
							</cmd-icon>
						</view> -->
					</view>
					<view class="cont">
						<uni-grid :column="5" :show-border="false"  :square="false" @change="goLink2">
						    <uni-grid-item v-for="(item,index) in usableMenuList" :index="index" :key="index">
						        <view class="name" :class="['om-bg-'+item.bgColor,{'text-height': item.text.length>4}]">{{ item.text }}</view>
						    </uni-grid-item>
						</uni-grid>
					</view>
				</view>
				<!-- <uni-collapse v-if="unusableMenuList.length" :accordion="true">
					<uni-collapse-item title="未启用" show-animation :showIconText="true">
						<om-menu :menuList="unusableMenuList" colLen="5" :bordered="false" fontSize="small" @click="changeMenu2"></om-menu>
					</uni-collapse-item>
				</uni-collapse> -->
				<om-bottomline content="让企业管理变得简单！" title="素伊OM系统"></om-bottomline>
			</view>
		</view>
		<!-- #ifdef H5 -->
		<view v-if="!hasLogin" class="hello padding">
			<view class="title">您好 游客！</view>
			<view class="ul">
				<view>这是“企业数字化运营管理系统”手机版“<text class="text-blue">素伊OM系统</text>”，请在 “我的” 中点击 “登录”。</view>
			</view>
		</view>
		<!-- #endif -->
		<!-- #ifdef APP || APP-PLUS || APP-NVUE || APP-PLUS-NVUE || APP-VUE -->
		<ot-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="CAMERA"></ot-authpup>
		<!-- #endif -->
	</om-page>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'pinia';
	import {
		useLoginUserStore
	} from '@/stores/login-user.js';
	import {
		confirmModal,
		addAutoLoginTimes,
		clearAutoLoginTimes
	} from '../../../static/js/common.js'
	import urlUtil from '@/static/js/urlUtil.js';
	const app = getApp();
	export default {
		data() {
			return {
				orgImages:[],
				showSkeleton: true,
				total: 0,
				total2: 0,
				total3:0,
				wxMenuList: [],
				notifyMenuList: [{
						title: '已参与',
						url: '../launch/launch'
					},
					{
						title: '待处理',
						url: '../pending/pending'
					},
					{
						title: '未阅读',
						url: '../unread/unread'
					},{
						title: '近期工作',
						url: '../work/work'
					}
				],
				//常用工具
				commonMenuLit: [],
				//可用模块
				usableMenuList: [],
				//停用模块
				unusableMenuList: [],
				pageTitle: "",
				colorList: this.ColorList,
				//topbutton高度
				topButtonHeight:0,
				affairsHeight:0,
				allGroupList: [],
				pushmessage: '',
				filterList: [{
					title: '',
					defaultTitle: '',
					key: 'orgSite',
					isSort: true,
					reflexTitle: false,
					defaultSelectedIndex: 0,
					detailList: [{
						'title': '',
						'value': '',
						'key': ''
					}]
				}],
				operateShow: false,
				promotionShow: false,
				processFormCount: 0,
				registrationFormCount: 0,
			};
		},
		provide() {
			return {
				searchKey: this
			}
		},
		computed: {
			...mapState(useLoginUserStore, ['forcedLogin', 'hasLogin', 'userName','orgName', 'mobile', 'orgShortName', 
			'isadmin', 'pendingReload', 'unreadReload', 'recentWorkReload','userId', 'orgId',
			'hasEmployeeRole', 'hasExternalStakeholdersRole']),
			marginTopAffairs(){
				return (this.affairsHeight+this.topButtonHeight)+15+'px'
			}
		},
		watch:{
			total(newValue, oldValue) {
				//#ifdef APP-PLUS
				plus.runtime.setBadgeNumber(this.total);
				//#endif
			},
			// total2(newValue, oldValue) {
			// 	//#ifdef APP-PLUS
			// 	plus.runtime.setBadgeNumber(this.total + this.total2);
			// 	//#endif
			// },
			deep:true
		},
		methods: {
			...mapMutations(useLoginUserStore, [
				'login',
				'logout',
				'setPending',
				'setUnread',
				'setRecentWork',
				'setToken'
			]),
			searchTab() {
				uni.navigateTo({
					url: "/pages/base/addr/phone/search"
				});
			},
			groupSetting(){
				uni.navigateTo({
					url: "/pages/main/group/setting"
				});
			},
			groupSync(){
				let _that = this;
				uni.showModal({
					title: '提示',
					content: '菜单已同步！',
					showCancel: false,
					success(res){
						if(res.confirm){
							_that.getGroupList()
						}
					}
				})
			},
			groupManager(item){
				uni.navigateTo({
					url: "/pages/main/group/group?groupId="+item.id
				});
			},
			operateMore(){
				this.operateShow = !this.operateShow
			},
			scanHandle(){
				let _that = this;

				// setTimeout(()=>{
				// 	_that.$refs['authpup'].open();
				// },500)
				
				uni.showModal({
					title: '对相机权限申请说明',
					content: '便于您使用该功能拍照、扫码等功能,是否使用？',
					cancelText: "否", 
					confirmText: "是",
					showCancel: true,
					success: (res) => {
						if(res.confirm) { 
							uni.scanCode({
							    onlyFromCamera: true,
								scanType: ['qrCode'],
							    success: function (res) {
									let data = JSON.parse(res.result)
									if(data.intervalTime){//动态二维码
										let yxdate = data.date + data.intervalTime
										let dqdate = new Date().getTime()
										if(yxdate>dqdate){
											uni.setStorageSync('scanCodeResultCache',res.result)
											_that.operateShow = false
											uni.navigateTo({
											    url: '/pages/scan/scanResult/scanResult'
											})
										}else{
											uni.showToast({
												title: '二维码已失效，请重新获取二维码！',
												icon: 'none',
												duration: 2000
											})
											_that.operateShow = false
										}
									}else{//静态二维码
										uni.setStorageSync('scanCodeResultCache',res.result)
										_that.operateShow = false
										uni.navigateTo({
										    url: '/pages/scan/scanResult/scanResult'
										})
									}
							    },
								fail: function(msg){
									_that.operateShow = false
									uni.showToast({
										title: msg,
										icon: 'none',
										duration: 2000
									})
								}
							});
						}
					}
				})
				
					// uni.scanCode({
					//     onlyFromCamera: true,
					// 	scanType: ['qrCode'],
					//     success: function (res) {
					// 		let data = JSON.parse(res.result)
					// 		if(data.intervalTime){//动态二维码
					// 			let yxdate = data.date + data.intervalTime
					// 			let dqdate = new Date().getTime()
					// 			if(yxdate>dqdate){
					// 				uni.setStorageSync('scanCodeResultCache',res.result)
					// 				_that.operateShow = false
					// 				uni.navigateTo({
					// 				    url: '/pages/scan/scanResult/scanResult'
					// 				})
					// 			}else{
					// 				uni.showToast({
					// 					title: '二维码已失效，请重新获取二维码！',
					// 					icon: 'none',
					// 					duration: 2000
					// 				})
					// 				_that.operateShow = false
					// 			}
					// 		}else{//静态二维码
					// 			uni.setStorageSync('scanCodeResultCache',res.result)
					// 			_that.operateShow = false
					// 			uni.navigateTo({
					// 			    url: '/pages/scan/scanResult/scanResult'
					// 			})
					// 		}
					//     },
					// 	fail: function(msg){
					// 		_that.operateShow = false
					// 		uni.showToast({
					// 			title: msg,
					// 			icon: 'none',
					// 			duration: 2000
					// 		})
					// 	}
					// });
			},
			headChange(e) {
				let {
					index
				} = e
				uni.navigateTo({
					url: this.notifyMenuList[index].url
				});
			},
			loadMenu() {
				let _that = this
				// uni.setNavigationBarTitle({
				// 	title: _that.orgShortName
				// });
				// _that.pageTitle = _that.orgShortName
				_that.loadCommonMenu()
				// _that.loadUsableMenu()
				// _that.loadUnusableMenu()
			},
			hotUpdate(res){
				let _that = this
				clearAutoLoginTimes()
				_that.login(res.value);
				_that.loadMenu()
				_that.pendingFunc()
				_that.unreadFunc()
				_that.recentWorkFunc()
				_that.getImages()
				//#ifdef APP-PLUS
				//判断是否有新版本进行更新
				plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {	
					let appUrl = 'https://zst.om909.com/';
				
					uni.request({  
					    url: appUrl+'version/checkVersion.do',  
					    data: {  
					        version: widgetInfo.version,
					        name: widgetInfo.name,  
							platform: uni.getSystemInfoSync().platform,
							serverUrl: getApp().globalData.url
					    },  
					    success: (res) => { 
							if(res.data.succeed){
								let data = res.data.value;
								let fileSize = data.fileSize;
								if(data.update && data.url){
									//热更新版本或者安卓版本
									if((data.url.substring(data.url.length-3,data.url.length) == 'wgt') || (data.url.substring(data.url.length-3,data.url.length) == 'apk')){
										if(data.msg){
											uni.showModal({
												title: '版本更新',
												content: data.msg,
												showCancel: false,
												success(res){
													if(res.confirm){
														plus.nativeUI.closeWaiting();
														plus.runtime.quit();  
													}
												}
											})
										}else{
											uni.showModal({
												title: '版本更新',
												content: '当前存在新版本，请进行更新！本次更新大小为'+fileSize,
												showCancel: false,
												success(res){
													if(res.confirm){
														plus.nativeUI.showWaiting("下载更新文件...");
														uni.downloadFile({
															url: appUrl+data.url,  
															success: (downloadResult) => {  
																if (downloadResult.statusCode === 200) {  
																	plus.nativeUI.closeWaiting();
																	plus.nativeUI.showWaiting("正在安装文件...");
																	plus.runtime.install(downloadResult.tempFilePath, {
																		force: false  
																	}, function() {  
																		plus.nativeUI.closeWaiting();
																		plus.runtime.restart();  
																	}, function(e) {  
																		plus.nativeUI.closeWaiting(); 
																	});  
																}  
															},
															 fail: (msg) =>{
																plus.nativeUI.closeWaiting();
																_that.om.toast('网络异常！');
															 }
														});
													}
													if(res.cancel){
														plus.nativeUI.closeWaiting();
													}
												}
											})
										}
									}
									//苹果版本
									if(data.url.substring(data.url.length-3,data.url.length) == 'ipa'){
										if(data.msg){
											uni.showModal({
												title: '版本更新',
												content: data.msg,
												showCancel: false,
												success(res){
													if(res.confirm){
														plus.nativeUI.closeWaiting();
														plus.runtime.quit();
													}
												}
											})
										}else{
											uni.showModal({
												title: '版本更新',
												content: '当前存在新版本，请前往AppStore更新版本！',
												showCancel: true,
												success(res){
													if(res.confirm){
														let appleId= 1542963362
														plus.runtime.launchApplication({
															action: `itms-apps://itunes.apple.com/cn/app/id${appleId}?mt=8`
														}, function(e) {
															console.log('Open system default browser failed: ' + e.message);
														});
													}
												}
											})
										}
									}
								}
							}else{
								_that.om.toast(res.data.msg);
							}	
						}
					})
				}); 
				 //#endif
			},
			autoLogin() {
				let _that = this
				_that.om.request('loginSession/getLoginSession').then(res => {
					if (res.succeed && res.value && res.value.userid) {
						_that.om.request('temployee/isfirstLogin', {
						
						}).then(jres => {
							if(jres.succeed){
								if(jres.value.succeed){
									uni.showModal({
										title: '温馨提示',
										content: 'OM系统提醒您，出于安全考虑，建议修改初始登录密码。',
										cancelText: '暂不修改',
										confirmText: '修改',
										success(jsres){
											if(jsres.confirm){
												uni.navigateTo({
													url: "/pages/setting/resetPwd"
												});
											}else{
												_that.hotUpdate(res)
											}
										}
									})
								}else{
									_that.hotUpdate(res)
								}		
							}else{
								_that.om.toast(jres);
								_that.hotUpdate(res)
							}
						})
					} else {
						_that.reLaunch()
					}
				},err=>{
					_that.reLaunch()
				})
			},
			reLaunch() {
				addAutoLoginTimes()
				this.logout();
				let _that = this
				// #ifdef APP-NVUE || APP-PLUS || APP-PLUS-NVUE
				// uni.getStorage({
				// 	key: "ORG_SITE",
				// 	success(res) {
				// 		if (res.data) {
				// 			if(res.data.endsWith("/")){
				// 				app.globalData.url = res.data
				// 			}else{
				// 				app.globalData.url = res.data + "/"
				// 			}
				// 			uni.reLaunch({
				// 				url: "/pages/login/login/login"
				// 			})
				// 		}else{
				// 			uni.reLaunch({
				// 				url: "/pages/login/scancode/scancode"
				// 			})
				// 		}
				// 	},
				// 	fail() {
				// 		uni.reLaunch({
				// 			url: "/pages/login/scancode/scancode"
				// 		})
				// 	}
				// })
				// #endif
				uni.reLaunch({
					url: "/pages/login/login/login"
				})
				
			},
			pendingFunc() {
				let _that = this
				this.$nextTick(function(){
					if (_that.hasLogin) {
						_that.om.request('wxCommon/getPendingTotal', {}, 'get', true).then(res => {
							if (res.succeed) {
								_that.total = res.value;
							}
						});
					}
				})
			},
			//未读提示
			unreadFunc(){
				let _that = this
				this.$nextTick(function(){
					if (_that.hasLogin) {
						_that.om.request('wxCommon/getUnreadTotal', {}, 'get', true).then(res => {
							if (res.succeed) {
								_that.total2 = res.value;
							}
						});
					}
				})
			},
			//近期工作提示
			recentWorkFunc(){
				let _that = this
				this.$nextTick(function(){
					if (_that.hasLogin) {
						_that.om.request('tkeyWorkEvaluate/getNotCompleteWorkTotal', {}, 'get', true).then(res => {
							if (res.succeed) {
								_that.total3 = res.value;
							}
						});
					}
				})
			},
			loadFunc() {
				let _that = this;
				if (!_that.hasLogin) {
					// #ifdef H5 || APP-PLUS || APP-NVUE 
					_that.autoLogin()
					// #endif
					// #ifdef MP-WEIXIN
					uni.showModal({
						showCancel: !_that.forcedLogin,
						title: "提示",
						content: "点击确认进行登录",
						success: function(res) {
							if (res.confirm) {
								_that.reLaunch()
							}
						}
					})
					// #endif
				} else {
					_that.autoLogin()
				}
			},
			commonEdit() {
				let _that = this;
				var arr = _that.commonMenuLit.slice(0, _that.commonMenuLit.length - 1)
				var str = ''
				if (arr && arr.length) {
					str = arr.map(e => e.id).join(",")
				}
				uni.navigateTo({
					url: "../commonmenu/commonmenu?str=" + str
				})
			},
			sceneEdit() {
				uni.navigateTo({
					url: "../scenemenu/scenemenu"
				})
			},
			changeMenu(e) {
				let _that = this
				let m = _that.usableMenuList[e.index]
				this.navigateToMenu(m)
			},
			changeMenu2(e) {
				let _that = this
				let m = _that.unusableMenuList[e.index]
				this.navigateToMenu(m)
			},
			navigateToMenu(m) {
				let _that = this
				uni.setStorage({
					key: "sub-menu-list",
					data: m.menu
				})
				uni.navigateTo({
					url: "/pages/main/detailmenu/detailmenu?title=" + m.text
				})
			},
			workHourCanConfirm(){
				let _that = this
				_that.om.request(
					"attendConfirm/canConfirm"
				).then(res=>{
					for(let item of _that.commonMenuLit ){
						if(item.h5url === "/pages/mine/workhour/workhour"){
							_that.$set(item, "showDot", res.value)
						}
					}
				})
			},
			salarybillCanConfirm(){
				let _that = this
				_that.om.request(
					"salaryConfirm/canConfirm"
				).then(res=>{
					for(let item of _that.commonMenuLit ){
						if(item.h5url === "/pages/mine/salaryroll/salaryroll"){
							_that.$set(item,"showDot",res.value)
						}
					}
				})
			},
			loadCommonMenu() {
				let _that = this;
				_that.om.request('wxCommonMenu/getCommonMenuList', {}, 'get', true).then(res => {
					if (res.succeed) {
						var more = {
							text: "更多应用",
							iconCls: "/images/menus/more.png",
							h5url: "../moremenu/moremenu"
						}
						// // #ifdef H5
						// var scan = {
						// 	text: "扫一扫",
						// 	iconCls: "/images/others/wechat.png",
						// 	h5url: "../../scan/ddscan/ddscan"
						// }
						// // #endif
						
						_that.$nextTick(function() {
							// // #ifdef H5							
							// _that.commonMenuLit = [scan, ...res.value, more];
							// // #endif
							_that.commonMenuLit = [...res.value, more];
						})
						_that.loadUsableMenu()
						_that.loadUnusableMenu()
						_that.workHourCanConfirm()
						_that.salarybillCanConfirm()
						_that.getMessageInfo()
					}
				});
			},
			loadUsableMenu() {
				this.loadModel('sceneMenu/getPublishMenuList', true)
			},
			loadUnusableMenu() {
				this.loadModel('wxCommonMenu/getUnusableMenuList', false)
			},
			loadModel(url, usable) {
				let _that = this;
				_that.om.request(url, {}, 'get', true).then(res => {
					if (res.succeed) {
						var menuList = res.value.map((item, i) => {
							var text = ""
							if (~item.groupName.indexOf("管理")) {
								text = item.groupName.slice(0, item.groupName.length - 2)
							} else {
								text = item.groupName
							}
							var badgeText = ''
							if (!usable && this.isadmin && item.attributes && item.attributes.auth) {
								badgeText = "未授权"
							}
							return {
								id: item.id,
								text: text,
								bgColor: usable ? _that.CuColorList[item.id % 12].name : "",
								menu: item.menu,
								badgeText: badgeText
							}
						})
						usable ? (_that.usableMenuList = menuList) : (_that.unusableMenuList = menuList)
					}
				});
			},
			switchPc(){
				
			},
			goLink(e){
				let num = e.detail.index;
				let item = this.commonMenuLit[num]
				if(num >= this.commonMenuLit.length){
					return ""
				}
				let tempUrl = item.h5url
				if(!tempUrl){
					return ""
				}
				let url = tempUrl + '?title=' + item.text;
				if (item.durl) {
					url += '&durl=' + item.durl;
				}
				if (item.code) {
					url += '&code=' + item.code;
				}
				if (item.badgeText) {
					url += '&badgeText=' + item.badgeText;
				}
				uni.navigateTo({
				    url:url
				})
			},
			goLink2(e){
				let num = e.detail.index;
				let m = this.usableMenuList[num]
				this.navigateToMenu(m)
			},
			getImages(){
				let _that = this
				_that.om.request(
					"orgAvatar/getOrgAvatarList"
				).then(res=>{
					if(res.succeed && res.value && res.value.length){
						_that.orgImages = res.value
					}
				})
			},
			getGroupList(){
				let _that = this
				_that.om.request('wxNewGroupMenu/getGroupAppList', {
					groupStatus: true
				}).then(res => {
					if (res.succeed) {
						_that.allGroupList = res.value;
					}
				});
			},
			onChangeFilter(data, data2){
 				let _that = this
				// #ifndef H5
				if (data && data.orgSite && data.orgSite.endsWith("/")) {
					app.globalData.url = data.orgSite
				} else {
					app.globalData.url = data.orgSite + "/"
				}
				let arr = _that.filterList[0].detailList.filter(e => !!e.isSelected);
				if(arr.length){
					uni.setStorageSync('ORG_SITE', {
						site:arr[0].value,
						name:arr[0].title
					});
					_that.om.clearToken();
					_that.om.setToken(_that.mobile,"",arr[0].key);
					_that.om.request('loginCenter/henter',{mobile: _that.mobile},'post',false,{
						header: {
							'authKey': arr[0].key
						}
					}).then(res => {
						if(res.succeed){
							_that.setToken(res.value.token);
							_that.login(res.value.accountInfo);
							uni.reLaunch({
								url: "/pages/main/main/main"
							})
						}
					})
				}
				// #endif
				// #ifdef H5
				_that.om.request('loginCenter/chooseOrg',{
					orgId: data.orgin
				}).then(res => {
					
				})
				uni.setStorageSync('ORG_ORGID', data.orgin);
				// #endif
			},
			//推送消息做跳转
			getMessageInfo(){
				let _that = this;
				let payloadData2 = uni.getStorageSync('payloadData2');
				if(payloadData2){
					var obj = null;
					if(typeof payloadData2 === 'string'){
						obj = JSON.parse(payloadData2)
					}else{
					    obj = payloadData2;
					}
					if(obj instanceof Object){
						var obj2 = null;
						if(typeof obj.payload === 'string'){
							obj2 = JSON.parse(obj.payload)
						}else{
						    obj2 = obj.payload;
						}
						if(obj2.fileCode && obj2.busCode){
							uni.setStorageSync("payloadData2", "")
							setTimeout(function() {
								_that.om.getFormInfoByFileCode(obj2.fileCode, obj2.busCode);
							}, 2000);
						}
					}
				}
			},
			getOrgList(){
				let _that = this
				// #ifndef H5		
				_that.om.mateRequest('integrate/getOrgSite?phone=' + _that.mobile, {}, 'POST', {
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				}).then(res => {
					if(res.success){
						let orgSites = res.data;
						if(orgSites && orgSites.length) {
							let arr = [];
							for(let i=0; i<orgSites.length; i++){
								let obj = {};
								obj.title = orgSites[i].orgName
								obj.value = orgSites[i].orgSite
								obj.key = orgSites[i].key
								if(orgSites[i].orgName == _that.orgName) {
									_that.filterList[0].defaultSelectedIndex = i
									_that.filterList[0].title = orgSites[i].orgName
									_that.filterList[0].defaultTitle = orgSites[i].orgName
								}
								arr.push(obj)
							}
							_that.filterList[0].detailList = arr
							// _that.getMessageInfo()
						}
					}else{
					}
				})
				// #endif
				// #ifdef H5
				_that.om.request('torganization/getOrgList').then(res => {
					if(!uni.getStorageSync("ORG_USERID") || (uni.getStorageSync("ORG_USERID") != _that.userId)){
						let arr = [];
						for(let i=0; i<res.length; i++){
							let obj = {};
							obj.title = res[i].name
							obj.value = res[i].id
							if(res[i].id == _that.orgId){
								_that.filterList[0].defaultSelectedIndex = i
								_that.filterList[0].title = res[i].name
								_that.filterList[0].defaultTitle = res[i].name
							}
							arr.push(obj)
						}
						_that.filterList[0].detailList = arr
						
						uni.setStorageSync('ORG_USERID', _that.userId);
						uni.setStorageSync('ORG_ORGID', _that.orgId);
					}else{
						let arr = [];
						for(let i=0; i<res.length; i++){
							let obj = {};
							obj.title = res[i].name
							obj.value = res[i].id
							if(res[i].id == uni.getStorageSync("ORG_ORGID")){
								_that.filterList[0].defaultSelectedIndex = i
								_that.filterList[0].title = res[i].name
								_that.filterList[0].defaultTitle = res[i].name
							}
							arr.push(obj)
						}
						_that.filterList[0].detailList = arr
					}					
				});
				// #endif
			},
			changeAuth(){
				
			},
			getSystemTableInfo(){
				let _that = this
				_that.om.request('systemTableInfo/getDataGrid', {
					page: 1,
					rows: 20
				}).then(res => {
					let obj = res.rows[0];
					
					_that.promotionShow = true
					_that.processFormCount = obj.processFormCount
					_that.registrationFormCount = obj.registrationFormCount
					
					_that.om.request('/dataDict/getIntByCode', {
						code: "DD020021001"
					}).then(res => {
						if(res.succeed){
							setTimeout(function() {
								_that.promotionShow = false
								uni.setStorageSync('promotionTime', new Date().getTime());
							}, res.value * 1000)
						}
					})
				});
			},
			checkPromotionTime(){
				var promotionTime = uni.getStorageSync('promotionTime');
				if (!promotionTime) {
				    return true;
				}
				var currentTime = new Date().getTime();
				var timeDiff = currentTime - Number(promotionTime);
				var daysDiff = timeDiff / (1000 * 60 * 60 * 24); // 毫秒转天
				return daysDiff > 7;
			}
		},
		onNavigationBarButtonTap(obj){
			if(obj.type == 'menu') {
				const popmenu = uni.getSubNVueById('pop_menu')
				popmenu.show('auto', 300, () => {
				})
			}
		},
		onLoad() {
			let _that = this;

			//判断是否显示推广信息
			if(_that.checkPromotionTime()){
				//获取系统表信息
				_that.getSystemTableInfo()
			}
			
			
			//加载组织列表
			_that.getOrgList();
			// 页面加载时触发  
			_that.loadFunc()
			//#ifdef APP-PLUS
				plus.runtime.setBadgeNumber(0);
				if (_that.hasLogin) {
					let cid = uni.getStorageSync('clientid');
					_that.om.request('temployee/updatePushClientId',{
						userId: _that.userId,
						clientId: cid,
					},'post',false).then(res => {
					})
					
					let payloadData = uni.getStorageSync('payloadData');
					let obj = JSON.parse(payloadData)
					if(obj.fileId && obj.formCode){
						uni.setStorageSync("payloadData", "")
						_that.getFormInfo(obj.fileId, obj.formCode)
					}
				}			
			//#endif		
		},
		updated() {
			let _that = this
			let view = uni.createSelectorQuery().select(".om-topbutton");
			view.boundingClientRect(res=>{
				if(res){
					_that.topButtonHeight = res.height
				}
			}).exec()
			let view2 = uni.createSelectorQuery().select(".affairs");
			view2.boundingClientRect(res=>{
				if(res){
					_that.affairsHeight = res.height
				}
			}).exec()
			let view3 = uni.createSelectorQuery().select(".tui-grid");
			view3.boundingClientRect(res=>{
				if(res){
				}
			}).exec()
		},
		onShow() {
			let _that = this
			setTimeout(()=>{
			   uni.setNavigationBarTitle({
			   	title: _that.orgShortName
			   });
			   _that.pageTitle = _that.orgShortName
			},300)
			uni.removeStorageSync('pendingList')
			if(this.pendingReload){
				// setInterval(function () { 
				//     _that.pendingFunc()		
				// }, 3000); 
				_that.pendingFunc()
				_that.setPending(false)
			}
			if(this.unreadReload){
				_that.unreadFunc()
				_that.setUnread(false)
			}
			if(this.recentworkReload){
				_that.recentWorkFunc()
				_that.setRecentWork(false)
			}	
			uni.getStorage({
				key: 'common-menu-reload',
				success: function(res) {
					if (res.data) {
						_that.loadCommonMenu()
						uni.removeStorage({
							key: 'common-menu-reload'
						})
					}
				}
			})
			uni.getStorage({
				key: 'scene-menu-reload',
				success: function(res) {
					if (res.data) {
						_that.loadUsableMenu()
						uni.removeStorage({
							key: 'scene-menu-reload'
						})
					}
				}
			})
			if(_that.hasLogin){
				_that.workHourCanConfirm()
				_that.salarybillCanConfirm()
			}
			
			_that.getGroupList()
			// //#ifdef APP-PLUS
			// let pinf = plus.push.getClientInfo();
			// let cid = pinf && pinf.clientid || '';
			// _that.pushmessage = cid
			// //#endif
		},
		//页面相关事件处理函数--监听用户下拉动作
		onPullDownRefresh: function() {
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 2000)
			if (this.hasLogin) {
				this.loadFunc()
				this.pendingFunc()
				this.unreadFunc()
				this.recentWorkFunc()
			}
		},
		onReady:function(){
			
		}
	};
</script>

<style>
	.title {
		color: #8f8f94;
		margin-top: 25px;
	}

	.ul {
		font-size: 15px;
		color: #8f8f94;
		margin-top: 25px;
	}

	.ul>view {
		line-height: 25px;
	}

	.affairs {
		box-shadow: 0 1px 10px #929191;
		/*for Android*/
		-webkit-box-shadow: 0px 1px 10px #b3b2b2;
		/*for IOS*/
		position: fixed;
		width: 100%;
		z-index: 10000;
		background: white;
	}

	.main-menu-text-pading-bigger {
		padding: 13px;
		text-align: center;
	}
</style>
<style lang="scss" scoped>
	.box-cont{
		font-size: 14px;
		color: #333333;
		font-family: Helvetica Neue, Helvetica, sans-serif;
		.tit-bar{
			display: -webkit-box;
			display: -webkit-flex;
			display: flex;
			position: relative;
			-webkit-box-orient: horizontal;
			-webkit-box-direction: normal;
			-webkit-flex-direction: row;
			flex-direction: row;
			padding: 12px 12px 0;
			-webkit-box-align: center;
			-webkit-align-items: center;
			align-items: center;
			.tit{
				    font-size: 14px;
				    -webkit-box-flex: 1;
				    -webkit-flex: 1;
				    flex: 1;
				    white-space: nowrap;
				    color: #333;
				    overflow: hidden;
				    text-overflow: ellipsis;
				    font-weight: bold;
			}
			.edit{
				-webkit-box-flex: 1;
				    -webkit-flex: 1;
				    flex: 1;
				    margin-left: 8px;
				    font-size: 14px;
				    text-align: right;
				    color: #999;
			}
			.manager-icon{
				width: 12px;
				height: 12px;
			}
		}
		.cont{
			// padding: 12px 12px 0;
			.cont-bg{
				
			}
			.item{
				padding: 15px 0;
			}
			.img{
				width: 25px;
				height: 25px;
				margin-bottom: 5px;
			}
			.name{
				width: 64px;
				height: 64px;
				line-height: 64px;
				font-size: 14px;
				background-color: #ccc;
				color: #FFF;
				margin: 15px 0;
				text-align: center;
				border-radius: 3px;
				white-space: normal !important;
				-webkit-box-direction: normal;
				user-select: none;
			}
			.text-height{
				height: 64px;
				line-height: 20px;
				padding: 12px 0;
			}
			.marker{
				height: 20rpx;
				width: 20rpx;
				border-radius: 10rpx;
				position: absolute;
				top: -10rpx;
				right: 50rpx;
				background-color: #DD524D;
			}
		}
	}
	
	.group-menu{
		height: 40px;
		line-height: 40px;
		padding-left: 32px;
		font-size: 14px;
		font-weight: bold;
		color: #0081ff;
		background: url("@/static/images/others/add-groupmenu.png") no-repeat;
		background-size: 16px 16px;
		background-position: 12px 12px;
	}
	.group-menu.sync{
		background: url("@/static/images/others/sync-groupmenu.png") no-repeat;
		background-size: 16px 16px;
		background-position: 12px 12px;
	}
	.topbg{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: var(--status-bar-height);
		z-index: 99999;
	}
	.topcont{
		/*  #ifdef APP  */
		margin-top: var(--status-bar-height);
		/*  #endif  */
		height: 32px;
		width: 100%;
		.topcont-org{
			float: left;
			width: calc(100% - 32px);
		}
		.topcont-more{
			float: left;
			width: 44px;
			height: 40px;
			background: url("@/static/images/others/operate-mores.png") no-repeat;
			background-size: 24px 24px;
			background-position: 10px 8px;
			position: fixed;
			right: 0;
			z-index: 999;
		}
		.topcont-more-sjx{
			position: absolute;
			right: 4px;
			top: 45px;
			z-index: 9999999;
			width: 0; 
			height: 0; 
			border-left: 16px solid transparent; 
			border-right: 16px solid transparent; 
			border-bottom: 16px solid rgba(0,0,0,1);
			/*  #ifdef APP  */
			top: 70px;
			/*  #endif  */
		}
		.topcont-more-list{
			position: absolute;
			right: 5px;
			top: 51px;
			z-index: 99999999;
			width: 130px;
			padding: 5px;
			background: rgba(0,0,0,1);
			color: #FFF;
			border-radius: 5px;
			/*  #ifdef APP  */
			top: 76px;
			/*  #endif  */
			.single{
				font-size: 14px;
				padding-left: 42px;
				width: 100%;
				height: 36px;
				line-height: 36px;
				border-bottom: 1px solid rgba(255,255,255,0.3);
			}
			.wechat{
				background: url("@/static/images/others/operate-wechat.png") no-repeat;
				background-size: 24px 24px;
				background-position: 10px 5px;
			}
		}
	}
	.promotion{
		position: fixed;
		top: 0;
		bottom: 0;
		width: 100%;
		height: 100%;
		z-index: 9999999999;
		color: #FFF;
		text-align: center;
		font-size: 16px;
		.cont{
			padding-top: 50px;
			text-align: left;
			width: 100%;
			margin-top: 80%;
			margin-left: 25%;
		}
	}
	.fade-enter-active, .fade-leave-active {
	  transition: opacity 0.5s;
	}
	.fade-enter, .fade-leave-to{
	  opacity: 0;
	}
</style>